package com.example.utils;

import com.example.annotation.Autowired;
import com.example.annotation.Component;

import java.sql.SQLException;

/**
 * 标记@Component
 * 定义似有属性 connectionUtils
 *
 * @author kangshuai
 */
@Component
public class TransactionManager {

    @Autowired
    private ConnectionUtils connectionUtils;


    /**
     * 开启手动事务控制
     *
     * @throws SQLException
     */
    public void beginTransaction() throws SQLException {
        connectionUtils.getCurrentThreadConn().setAutoCommit(false);
    }


    /**
     * 提交事务
     *
     * @throws SQLException
     */
    public void commit() throws SQLException {
        connectionUtils.getCurrentThreadConn().commit();
    }


    /**
     * 回滚事务
     *
     * @throws SQLException
     */
    public void rollback() throws SQLException {
        connectionUtils.getCurrentThreadConn().rollback();
    }
}
